Add rdoc to unescape_replacement

Akinori MUSHA 9 years ago
parent
commit
b707b683e4
1 changed files with 26 additions and 0 deletions
  1. 26 0
      app/concerns/liquid_interpolatable.rb

+ 26 - 0
app/concerns/liquid_interpolatable.rb

@@ -236,6 +236,32 @@ module LiquidInterpolatable
236 236
       "v" => "\v",
237 237
     }
238 238
 
239
+    # Unescape a replacement text for use in the second argument of
240
+    # gsub/sub.  The following escape sequences are recognized:
241
+    #
242
+    # - "\\" (backslash itself)
243
+    # - "\a" (alert)
244
+    # - "\b" (backspace)
245
+    # - "\e" (escape)
246
+    # - "\f" (form feed)
247
+    # - "\n" (new line)
248
+    # - "\r" (carriage return)
249
+    # - "\s" (space)
250
+    # - "\t" (horizontal tab)
251
+    # - "\u{XXXX}" (unicode codepoint)
252
+    # - "\v" (vertical tab)
253
+    # - "\xXX" (hexadecimal character)
254
+    # - "\1".."\9" (numbered capture groups)
255
+    # - "\+" (last capture group)
256
+    # - "\k<name>" (named capture group)
257
+    # - "\&" or "\0" (complete matched text)
258
+    # - "\`" (string before match)
259
+    # - "\'" (string after match)
260
+    #
261
+    # Octal escape sequences are deliberately unsupported to avoid
262
+    # conflict with numbered capture groups.  Rather obscure Emacs
263
+    # style character codes ("\C-x", "\M-\C-x" etc.) are also omitted
264
+    # from this implementation.
239 265
     def unescape_replacement(s)
240 266
       s.gsub(/\\(?:([\d+&`'\\]|k<\w+>)|u\{([[:xdigit:]]+)\}|x([[:xdigit:]]{2})|(.))/) {
241 267
         if c = $1